package com.leyou.item.mapper;


import com.leyou.item.pojo.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface CategoryMapper extends Mapper<Category>, SelectByIdListMapper<Category,Long> {
    //根据品牌ID来查询分类信息进行回显,因为查询涉及到两张表，故无法使用通用mapper
    //使用注解式书写sql语句
    @Select("select * from tb_category where id in " +
            "(select category_id from tb_category_brand where brand_id = #{bid})")
    List<Category> queryByBrand(@Param("bid") Long bid);


    //添加新节点的同时，修改原节点的父结点标示为1
    @Update("update tb_category set is_parent = 1 where id = #{pid}")
    void updateOldCode(@Param("pid") Long pid);

    //删除父节点时，删除子节点的parentId是参数“id”的子节点
    @Delete("delete from tb_category where parent_id = #{id} ")
    void delSonCode(@Param("id") Long id);
}
